package com.start.workflow.core.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.start.common.api.Result;
import com.start.common.dataRule.DataQueryConstructor;
import com.start.common.utils.TreeModelUtils;
import com.start.workflow.core.service.StartActCategoryService;
import com.start.workflow.entity.StartActCategory;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Tag(name = "流程类别API")
@RequestMapping("/startActCategoryApi")

public class StartActCategoryApi {
    @Autowired
    private StartActCategoryService actCategoryService;

    @GetMapping("/listCategory")
    public Result<?> listCategory(@RequestParam(required = false, defaultValue = "false") Boolean isTree) {
        QueryWrapper<StartActCategory> queryWrapper = DataQueryConstructor.createEntity(StartActCategory.class);
        List<StartActCategory> list = actCategoryService.list(queryWrapper);
        if (!isTree) {
            return Result.ok(list);
        }
        return Result.ok(TreeModelUtils.createTree(list));
    }

}
